package pl.edu.agh.mgr.hotel.ws;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.ws.BindingProvider;

public class WSClient {
	public static DataResponse getHotelData(String wsName,
			DataRequest dataRequest) {

		final String wsAddress = "http://localhost:8081/" + wsName
				+ "/services/DataServicePort";
		try {
			DataService.WSDL_LOCATION = new URL("http://localhost:8080/"
					+ wsName + "/services/DataServicePort?wsdl");
		} catch (MalformedURLException e) {
			java.util.logging.Logger
					.getLogger(DataService.class.getName())
					.log(java.util.logging.Level.INFO,
							"Can not initialize the default wsdl from {0}",
							"http://localhost:8080/Hotel/services/DataServicePort?wsdl");
		}

		DataService ss = new DataService();
		DataServicePortType port = ss.getDataServicePort();

		BindingProvider provider = (BindingProvider) port;
		provider.getRequestContext().put(
				BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsAddress);

		return port.getHotelData(dataRequest);
	}
}
